<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">
<body>
    <ui:composition template="/WEB-INF/template.xhtml">
        <ui:define name="topnav">
            <ui:include src="/WEB-INF/incl/cust_nav.xhtml">
                <ui:param name="page" value="browse"/>
            </ui:include>
        </ui:define>

        <ui:define name="sidebar">
            <ui:include src="/WEB-INF/incl/login.xhtml" />
        </ui:define>

        <ui:define name="body">
            <h:messages globalOnly="true" 
                        layout="list" 
                        errorClass="cntError"/>
            
            <div class="controlBar" style="clear: left;">
                <div style="padding: 3px 6px; vertical-align: bottom;">
                    Shopping Cart
                </div>
            </div>

            <c:choose>
                <c:when test="#{empty(cart.cart)}">
                    <p>Your cart is empty.</p>
                </c:when>
                <c:otherwise>

                    <h:form>
                        <h:dataTable value="#{cart.cart}" var="item"
                                     styleClass="dvdtable" 
                                     headerClass="dvdtablehead"
                                     rowClasses="dvdtableodd,dvdtableeven"
                                     columnClasses="dvdtablecol">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msgs.cartRemoveColumn}" />
                                </f:facet>
                                <h:selectBooleanCheckbox value="#{cart.cartSelection[item]}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msgs.cartTitleColumn}" />
                                </f:facet>
                                <h:outputText value="#{item.product.title}" />
                            </h:column>                        
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msgs.cartActorColumn}" />
                                </f:facet>
                                <h:outputText value="#{item.product.actor}" />
                            </h:column>                        
                            
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msgs.cartPriceColumn}" />
                                </f:facet>
                                <h:outputText value="#{item.product.price}">
                                    <f:convertNumber type="currency" currencySymbol="$" />
                                </h:outputText>
                            </h:column>                        
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="#{msgs.cartQuantityColumn}" />
                                </f:facet>
                                <h:inputText value="#{item.quantity}" size="6" />
                            </h:column>                        
                        </h:dataTable>
                        <h:commandButton action="#{cart.updateCart}" value="#{msgs.checkoutUpdateButton}" />
                    </h:form>

                    <div style="width: 100%;">
                        <div class="cntInfo" style="float:right;">
                            <h:panelGrid columns="2">
                                <h:outputText value="#{msgs.checkoutSubtotal}" />
                                <h:outputText value="#{cart.subtotal}">
                                    <f:convertNumber type="currency" currencySymbol="$" />
                                </h:outputText>
                                
                                <h:outputText value="#{msgs.checkoutTax}" />
                                <h:outputText value="#{cart.tax}">
                                    <f:convertNumber type="currency" currencySymbol="$" />
                                </h:outputText>
                                
                                <h:outputText value="#{msgs.checkoutTotal}" />
                                <h:outputText value="#{cart.total}">
                                    <f:convertNumber type="currency" currencySymbol="$" />
                                </h:outputText>
                            </h:panelGrid>
                            
                            <h:form>
                                <h:commandButton action="#{cart.purchase}"  
                                                 value="#{msgs.checkoutPurchaseButton}" />
                            </h:form>
                        </div>
                    </div>
                </c:otherwise>
            </c:choose>
        </ui:define>
    </ui:composition>
</body>
</html>
